#
# @lc app=leetcode.cn id=66 lang=python3
#
# [66] 加一
#

# @lc code=start
class Solution:
    def plusOne(self, digits: List[int]) -> List[int]:
        #solution1:暴力计算，python特有
        #python的int长度可以很长很长很长...
        # numbers = 0
        # digLength = len(digits)
        # for i in range(digLength):
        #     numbers += digits[i] * (10**(digLength - i - 1))
        # numbers += 1
        
        # numbers = list(str(numbers))
        
        # for i in range(len(numbers)):
        #     numbers[i] = int(numbers[i])
        # return numbers

        #solution2:
        digLength = len(digits)
        carryFlag = True
        
        while digLength > 0 and carryFlag:
            if digits[digLength - 1] == 9:
                digits[digLength - 1] = 0
                digLength -= 1
            else:
                digits[digLength - 1] += 1
                return digits
        digits.insert(0, 1)
        return digits
            
            
# @lc code=end

